xm-test: add tests for network-attach command
authorroot@localhost.localdomain <root@localhost.localdomain>
Wed, 23 Nov 2005 11:32:44 +0000 (12:32 +0100)
committerroot@localhost.localdomain <root@localhost.localdomain>
Wed, 23 Nov 2005 11:32:44 +0000 (12:32 +0100)
Signed-off-by: Murillo Fernandes Bernardes <mfb@br.ibm.com>
tools/xm-test/configure.ac
tools/xm-test/tests/Makefile.am
tools/xm-test/tests/network-attach/01_network_attach_pos.py [new file with mode: 0644]
tools/xm-test/tests/network-attach/02_network_attach_detach_pos.py [new file with mode: 0644]
tools/xm-test/tests/network-attach/03_network_attach_detach_multiple_pos.py [new file with mode: 0644]
tools/xm-test/tests/network-attach/04_network_attach_baddomain_neg.py [new file with mode: 0644]
tools/xm-test/tests/network-attach/Makefile.am [new file with mode: 0644]
tools/xm-test/tests/network-attach/network_utils.py [new file with mode: 0644]

index 5bfa2d1d529b8d869b465cae9bd05cdec838b255..224d5fa1295c89f5421356d9b69b3710ca511278 100644 (file)
@@ -50,6 +50,7 @@ AC_CONFIG_FILES([
     tests/memmax/Makefile
     tests/memset/Makefile
     tests/migrate/Makefile
+    tests/network-attach/Makefile
     tests/pause/Makefile
     tests/reboot/Makefile
     tests/restore/Makefile
index 45484ab7c6770dfd4b882fb156a810050166626c..8ce2c04ff1212e8ccc636c0374ec3d302203e67e 100644 (file)
@@ -13,6 +13,7 @@ SUBDIRS =                     \
                list            \
                memmax          \
                memset          \
+               network-attach  \
                pause           \
                reboot          \
                sedf            \
diff --git a/tools/xm-test/tests/network-attach/01_network_attach_pos.py b/tools/xm-test/tests/network-attach/01_network_attach_pos.py
new file mode 100644 (file)
index 0000000..b2a491b
--- /dev/null
@@ -0,0 +1,48 @@
+#!/usr/bin/python
+
+# Copyright (C) International Business Machines Corp., 2005
+# Author: Murillo F. Bernardes <mfb@br.ibm.com>
+
+import sys
+
+from XmTestLib import *
+from network_utils import *
+
+# Create a domain (default XmTestDomain, with our ramdisk)
+domain = XmTestDomain()
+
+try:
+    domain.start()
+except DomainError, e:
+    if verbose:
+        print "Failed to create test domain because:"
+        print e.extra
+    FAIL(str(e))
+
+# Attach a console to it
+try:
+    console = XmConsole(domain.getName(), historySaveCmds=True)
+except ConsoleError, e:
+    FAIL(str(e))
+
+try:
+    # Activate the console
+    console.sendInput("input")
+    # Run 'ls'
+    run = console.runCmd("ls")
+except ConsoleError, e:
+    saveLog(console.getHistory())
+    FAIL(str(e))
+    
+## Real test
+status, msg = network_attach(domain.getName(), console)
+if status:
+    FAIL(msg)
+
+
+##
+# Close the console
+console.closeConsole()
+
+# Stop the domain (nice shutdown)
+domain.stop()
diff --git a/tools/xm-test/tests/network-attach/02_network_attach_detach_pos.py b/tools/xm-test/tests/network-attach/02_network_attach_detach_pos.py
new file mode 100644 (file)
index 0000000..7e4559a
--- /dev/null
@@ -0,0 +1,54 @@
+#!/usr/bin/python
+
+# Copyright (C) International Business Machines Corp., 2005
+# Author: Murillo F. Bernardes <mfb@br.ibm.com>
+
+import sys
+import re
+import time
+
+from XmTestLib import *
+from network_utils import *
+
+# Create a domain (default XmTestDomain, with our ramdisk)
+domain = XmTestDomain()
+
+try:
+    domain.start()
+except DomainError, e:
+    if verbose:
+        print "Failed to create test domain because:"
+        print e.extra
+    FAIL(str(e))
+
+# Attach a console to it
+try:
+    console = XmConsole(domain.getName(), historySaveCmds=True)
+except ConsoleError, e:
+    FAIL(str(e))
+
+try:
+    # Activate the console
+    console.sendInput("input")
+    # Run 'ls'
+    run = console.runCmd("ls")
+except ConsoleError, e:
+    saveLog(console.getHistory())
+    FAIL(str(e))
+
+## Real test - attach and detach
+status, msg = network_attach(domain.getName(), console)
+if status:
+    FAIL(msg)
+
+status, msg = network_detach(domain.getName(), console)
+if status:
+    FAIL(msg)
+
+
+
+# Close the console
+console.closeConsole()
+
+# Stop the domain (nice shutdown)
+domain.stop()
diff --git a/tools/xm-test/tests/network-attach/03_network_attach_detach_multiple_pos.py b/tools/xm-test/tests/network-attach/03_network_attach_detach_multiple_pos.py
new file mode 100644 (file)
index 0000000..e13e1ff
--- /dev/null
@@ -0,0 +1,54 @@
+#!/usr/bin/python
+
+# Copyright (C) International Business Machines Corp., 2005
+# Author: Murillo F. Bernardes <mfb@br.ibm.com>
+
+import sys
+import re
+import time
+
+from XmTestLib import *
+from network_utils import *
+
+# Create a domain (default XmTestDomain, with our ramdisk)
+domain = XmTestDomain()
+
+try:
+    domain.start()
+except DomainError, e:
+    if verbose:
+        print "Failed to create test domain because:"
+        print e.extra
+    FAIL(str(e))
+
+# Attach a console to it
+try:
+    console = XmConsole(domain.getName(), historySaveCmds=True)
+except ConsoleError, e:
+    FAIL(str(e))
+
+try:
+    # Activate the console
+    console.sendInput("input")
+    # Run 'ls'
+    run = console.runCmd("ls")
+except ConsoleError, e:
+    saveLog(console.getHistory())
+    FAIL(str(e))
+    
+for i in range(10):
+    print "Attaching %d device" % i 
+    status, msg = network_attach(domain.getName(), console)
+    if status:
+        FAIL(msg)
+    
+    print "Detaching %d device" % i 
+    status, msg = network_detach(domain.getName(), console, i)
+    if status:
+        FAIL(msg)
+
+# Close the console
+console.closeConsole()
+
+# Stop the domain (nice shutdown)
+domain.stop()
diff --git a/tools/xm-test/tests/network-attach/04_network_attach_baddomain_neg.py b/tools/xm-test/tests/network-attach/04_network_attach_baddomain_neg.py
new file mode 100644 (file)
index 0000000..838d66c
--- /dev/null
@@ -0,0 +1,17 @@
+#!/usr/bin/python
+
+# Copyright (C) International Business Machines Corp., 2005
+# Author: Murillo F. Bernardes <mfb@br.ibm.com>
+
+from XmTestLib import *
+
+status, output = traceCommand("xm network-attach NOT-EXIST")
+
+eyecatcher = "Error"
+where = output.find(eyecatcher)
+if status == 0:
+       FAIL("xm block-attach returned bad status, expected non 0, status is: %i" % status )
+elif where == -1:
+       FAIL("xm block-attach returned bad output, expected Error, output is: %s" % output )
+       
+
diff --git a/tools/xm-test/tests/network-attach/Makefile.am b/tools/xm-test/tests/network-attach/Makefile.am
new file mode 100644 (file)
index 0000000..00acf23
--- /dev/null
@@ -0,0 +1,24 @@
+
+SUBDIRS =
+
+TESTS = 01_network_attach_pos.test \
+       02_network_attach_detach_pos.test \
+       03_network_attach_detach_multiple_pos.test  \
+       04_network_attach_baddomain_neg.test
+
+DISABLED = 
+
+EXTRA_DIST = $(TESTS) $(XFAIL_TESTS) network_utils.py
+
+TESTS_ENVIRONMENT=@TENV@
+
+%.test: %.py
+       cp $< $@
+       chmod +x $@
+
+clean-local: am_config_clean-local
+
+am_config_clean-local:
+       rm -f *test
+       rm -f *log
+       rm -f *~
diff --git a/tools/xm-test/tests/network-attach/network_utils.py b/tools/xm-test/tests/network-attach/network_utils.py
new file mode 100644 (file)
index 0000000..a1ccdf6
--- /dev/null
@@ -0,0 +1,37 @@
+#!/usr/bin/python
+
+# Copyright (C) International Business Machines Corp., 2005
+# Author: Murillo F. Bernardes <mfb@br.ibm.com>
+
+from XmTestLib import *
+
+def count_eth(console):
+    try:
+        run = console.runCmd("ifconfig -a | grep eth")
+    except ConsoleError, e:
+        FAIL(str(e))
+    return = len(run['output'].splitlines())
+
+def network_attach(domain_name, console):
+    eths_before = count_eth(console)
+    status, output = traceCommand("xm network-attach %s" % domain_name)
+    if status != 0:
+        return -1, "xm network-attach returned invalid %i != 0" % status
+
+    eths_after = count_eth(console)
+    if (eths_after != (eths_before+1)):
+        return -2, "Network device is not actually connected to domU"
+
+    return 0, None 
+
+def network_detach(domain_name, console, num=0):
+    eths_before = count_eth(console)
+    status, output = traceCommand("xm network-detach %s %d" % (domain_name, num))
+    if status != 0:
+        return -1, "xm network-attach returned invalid %i != 0" % status
+
+    eths_after = count_eth(console)
+    if eths_after != (eths_before-1):
+       return -2, "Network device was not actually disconnected from domU"
+
+    return 0, None